// pages/yuangongqingjia/yuangongqingjia.js
Page({
    /**
     * 页面的初始数据
     */
    data: {
        b:'已驳回',
        t:'已通过',
        list2:'',
        list1:{},
        userId:'',
      startDate: '', // 开始日期（格式：YYYY-MM-DD）
      endDate: '',   // 结束日期
      duration: null ,// 时长（天数）
  range:[ 
  { id: 1, name: '年假' },
  { id: 2, name: '病假' },
  { id: 3, name: '事假' },
  { id: 4, name: '婚假' },
  { id: 5, name: '产假' }
  ],
//   selectedrange: '',
//   receivedValue:'',
//   receivedValue1:'',
//   receivedValue2:'',
//   receivedValue3:'',
//   receivedValue4:''

  
    },
    change1(e){
      const index = e.detail.value
      this.setData({
        selectedrange: this.data.range[index].name
      })
  },
  onStartDateChange(e) {
      this.setData({ startDate: e.detail.value });
      this.calculateDuration();
    },
  
    // 选择结束日期
    onEndDateChange(e) {
      this.setData({ endDate: e.detail.value });
      this.calculateDuration();
    },
    calculateDuration() {
      const { startDate, endDate } = this.data;
      if (!startDate || !endDate) return;
      // 转换为时间戳（毫秒）
      const start = new Date(startDate).getTime();
      const end = new Date(endDate).getTime();
      // 计算天数（取绝对值，避免结束时间早于开始时间）
      const days = Math.abs(Math.floor((end - start) / (1000 * 60 * 60 * 24)));
      this.setData({ duration: days })
    },
    shenpi(e){
        const that=this
        const tongguo={
            approvalStatus:that.data.t,
            userId:that.data.userId
        }
        wx.request({
          url: 'http://10.10.18.237:8080/leave/update1',
          data:tongguo
        })
    },
    bohui(e){
        const that=this
        const bo={
            approvalStatus:that.data.b,
            userId:that.data.userId
        }
        wx.request({
          url: 'http://10.10.18.237:8080/leave/update1',
          data:bo
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad:function(options) {
        const that=this
        console.log(options);
        that.setData({
            userId:options.userId
        })
        wx.request({
          url: 'http://10.10.18.237:8080/leave/select2?userId='+that.data.userId,
          success(res){
              console.log(res.data[0].user.name);
              that.setData({
                  list1:res.data,
                  list2:res.data[0].user.name
              })
          }
        })
        // console.log(options);
        // this.setData({
        //     receivedValue:options.selectedrange,
        //     receivedValue1:options.start,
        //     receivedValue2:options.end,
        //     receivedValue3:options.time,
        //     receivedValue4:options.liyou
        // })
    },
  
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {
  
    },
  
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
  
    },
  
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {
  
    },
  
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {
  
    },
  
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {
  
    },
  
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {
  
    },
  
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {
  
    }
  })
  